<?php

namespace App\Http\Controllers\Member;

use App\Http\Controllers\Controller;
use App\Rules\VerificationCodeRule;
use App\Services\CodeService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rule;

class MobileController extends Controller
{
    //
    public function create()
    {
        return view('member.mobile');
    }

    public function store(Request $request)
    {
        $user = Auth::user();
        $request->validate([
            'mobile' => ['required', 'regex:/^1\d{10}$/i', Rule::unique('users', 'mobile')->ignore($user->id)],
            'code' => [new VerificationCodeRule($request->mobile), 'required']
        ]);
        $user->mobile = $request->mobile;
        $user->save();
        return back()->with(['success'=>'手机绑定成功']);
    }


}
